import store from './store'
import router from './router'

router.beforeEach((to, form, next) => {
  const whilelist = ['/login', '404']
  const token = store.state.user.token
  if (token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    if (whilelist.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
